package cn.itcast.wushangxiantu.BaseAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.itcast.wushangxiantu.Activity.Login;
import cn.itcast.wushangxiantu.R;
import cn.itcast.wushangxiantu.UserData.UserChongWu;

public class ChongWuBagGriveViewAdapter extends BaseAdapter {
    private Context context;
    private UserChongWu chongWu;

    public ChongWuBagGriveViewAdapter(Context context) {
        this.context = context;
    }

    public UserChongWu getChongWu() {
        return chongWu;
    }

    public void setChongWu(UserChongWu chongWu) {
        this.chongWu = chongWu;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (null == chongWu) {
            return 0;
        } else {
            return chongWu.getChongwu().size();
        }
    }

    @Override
    public Object getItem(int i) {
        return chongWu.getChongwu().get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        view=View.inflate(context,R.layout.griveview_bag,null);
        ViewHolder viewHolder=new ViewHolder(view);
        viewHolder.tvName.setText(chongWu.getChongwu().get(i).getName());
        if (chongWu.getChongwu().get(i).getId()== Login.getUser().getCw_id()){
            viewHolder.tvNumber.setText("携带");
        }else {
            viewHolder.tvNumber.setVisibility(View.INVISIBLE);
        }
        return view;
    }

    class ViewHolder {
        public View rootView;
        public TextView tvName;
        public TextView tvNumber;
        public RelativeLayout li;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tvName = (TextView) rootView.findViewById(R.id.tvName);
            this.tvNumber = (TextView) rootView.findViewById(R.id.tvNumber);
            this.li = (RelativeLayout) rootView.findViewById(R.id.li);
        }

    }
}
